import urllib.request 
import re

# python 随机数
import random 
uapools=[
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36 Edg/80.0.361.69"
]
def UA():
  opener = urllib.request.build_opener()
  nowua = random.choice(uapools)
  ua = ("User-Agent", nowua )
  opener.addheaders = [ua]
  urllib.request.install_opener(opener)


pat = '<a class="recmd-content".*?>(.*?)</a>' 
mole = re.compile(pat,re.S) 
# for i in range(1,14):
for i in range(1,3):
  UA()
  url = "https://www.qiushibaike.com/8hr/page/"+str(i)+"/"
  print("第"+str(i)+"页数据:"+url)
  try :
    data=urllib.request.urlopen(url).read().decode("utf-8","ignore")
    res = mole.findall(data)
    for index in range(len(res)):
      print("\t"+str(index)+":"+ res[index])
  except Exception as err:
      print("o huo")
      pass